package com.weixing.mall.provider.controller.rpc;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.weixing.mall.base.enums.WhetherEnum;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.domain.SubSite;
import com.weixing.mall.provider.service.ISubSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/subsite")
public class SubSiteRpcController extends BaseController {
    @Autowired
    private ISubSiteService subSiteService;

    @GetMapping(value = "getSubSiteList")
    public List<Map<String,Object>> getSubSiteList(){
        QueryWrapper<SubSite> wrapper = new QueryWrapper<>();
        wrapper.eq("is_enable", WhetherEnum.YES.getValue()).orderByAsc("order_by");
        List<SubSite> list = subSiteService.list(wrapper);
        List<Map<String,Object>> mapList = Lists.newArrayList();
        list.forEach(subSite -> {
            Map map = new HashMap<String,Object>();
            map.put("id",subSite.getPartitionId());
            map.put("name",subSite.getSiteName());
            mapList.add(map);
        });
        return mapList;
    }
}
